'use strict';

var host = 'https://api.rayli.com.cn';
//3.0  http://api.rayli.com.cn/rlz3.0/doc.html
var api_3 = host + '/rlz3.0/index.php?';
var api_mz_3 = host + '/rlz3.0';
//4.0  http://api.rayli.com.cn/rlz4/doc.html
var api_4 = host + '/rlz4/index.php?';
var api_test = 'http://rayli.yicp.io' + '/rayliApi?';

var ajaxHeaders = {
    "content-type": "application/x-www-form-urlencoded",
    "encryptValue": "4JQ0bOX6OMRF0zst3b187bTzZsxTQhiRAS2Ub8Y77T6w5VEbY2HSFg=="
};

function obj2uri(obj) {
    return Object.keys(obj).map(function (k) {
        return encodeURIComponent(k) + '=' + encodeURIComponent(obj[k]);
    }).join('&');
}

module.exports = {
    // 获取试用列表
    getTrials: function (obj) {
        var url = api_3 + "m=try&a=newList&p=" + obj.page + "&uid=" + obj.userId;
        console.log("getTrials - " + url);
        return url;
    },

    getTrialDetail: function (obj) {
        return api_3 + "m=try&a=show&id=" + obj.id + "&uid=0" + obj.userId;
    },

    getTrialTags: function (id, obj) {
        return api_3 + "m=try&a=getTryTags&tid=" + id + "&uid=0";//申请试用-标签列表	 &tid=1458
    },

    getSmsCode: function () {
        return api_3 + "m=user&a=sendMCode";
    },

    mobileLogin: api_mz_3 + "/index.php?m=user&a=mobileLogin", //手机号+短信验证码登录	&mobile=15311489278&code=778899
    tryApply: api_3 + "&m=try&a=tryApply", //申请试用	tags=提拉紧致&tryout_id=1333&title=雅诗兰黛全新肌透修护精萃蜜&user_id=12669801&reason=aaa,

    myTrial: function (obj) {
        var url = api_3 + "m=user&a=getMyTry&uid=" + obj.userId + "&opt=" + obj.opt + "&p=" + obj.page; //我的试用	 &opt=1&uid=2675373 （ opt 1=全部 2=申请成功 3=待收货 4=待提交）
        console.log("url - myTrial - " + url);
        return url;
    },
    personalInfo: function (obj) {
        var url = api_3 + "m=user&a=getPersonalInfo&followId="+obj.userId;//根据followId获得用户信息		&followId=2320665&uid=12669801
        console.log("url - myTrial - " + url);
        return url;
    },
    headers: ajaxHeaders
};